﻿using System;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Transactions;

public partial class Main_ServiceInvoice_TransactionFormat_RecieptFormat : System.Web.UI.Page
{
    Datautility DU = new Datautility();
    string strsql = string.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["userid"] == null)
        {
            Response.Redirect("~/SessionExpired.aspx");
        }
        if (!IsPostBack)
        {
            if (Request.QueryString["action"] != null)
            {
                if (Request.QueryString["action"].ToString() == "addnew")
                {
                    PnlAddNew.Visible = true;

                    _BindTdsHeadAccounts();
                    _BindWriteOffAccounts();

                }
                else if (Request.QueryString["action"].ToString() == "view")
                {
                    PnlView.Visible = true;

                    _BindGridViewData();


                    if (Request.QueryString["msg"] != null)
                    {
                        if (Request.QueryString["msg"].ToString() == "true")
                        {
                            lblMsg.Attributes.Add("class", "true");
                            lblMsg.Text = "Reciept Format Created Successfully..";
                            lblMsg.Focus();
                        }
                        else if (Request.QueryString["msg"].ToString() == "Update")
                        {
                            lblMsg.Attributes.Add("class", "true");
                            lblMsg.Text = "Reciept Format Updated Successfully..";
                            lblMsg.Focus();
                        }
                    }
                    else
                    {
                        lblMsg.Text = "";
                    }

                }
                else if (Request.QueryString["action"].ToString() == "Edit")
                {

                    if (Request.QueryString["FormatId"] != null)
                    {
                        if (Request.QueryString["Status"].ToString() == "Edit")
                        {
                            PnlAddNew.Visible = true;

                            _BindTdsHeadAccounts();
                            _BindWriteOffAccounts();
                            _BindEditTranFormat_Main(Request.QueryString["FormatId"].ToString());
                            hidFormatId.Value = Request.QueryString["FormatId"].ToString();
                            btnSave.Text = "Update";

                        }
                    }
                }
            }
        }
    }
    private void _BindTdsHeadAccounts()
    {
        SqlParameter[] sparam =
                                {
                                    new SqlParameter("@TYPE","0")

                                };
        DataTable DT = DU.getdatausingprocedure("USP_IVC_GetTDSAccountLedgerForSettings", sparam);
        if (DT.Rows.Count > 0)
        {
            ddlTDSAccounts.DataSource = DT;
            ddlTDSAccounts.DataTextField = "LNAME";
            ddlTDSAccounts.DataValueField = "LID";
            ddlTDSAccounts.DataBind();
        }
    }
    private void _BindWriteOffAccounts()
    {
        SqlParameter[] sparam =
                                {
                                    new SqlParameter("@TYPE","1")

                                };
        DataTable DT = DU.getdatausingprocedure("USP_IVC_GetTDSAccountLedgerForSettings", sparam);
        if (DT.Rows.Count > 0)
        {
            ddlWriteOffAccount.DataSource = DT;
            ddlWriteOffAccount.DataTextField = "LNAME";
            ddlWriteOffAccount.DataValueField = "LID";
            ddlWriteOffAccount.DataBind();
        }
    }
    protected void btnSave_OnClick(object sender, EventArgs e)
    {
        try
        {
            using (TransactionScope scope = new TransactionScope())
            {
                _SaveTranFormatMain(hidFormatId.Value);
                scope.Complete();
            }
            if (btnSave.Text == "Save")
            {
                Response.Redirect("RecieptFormat.aspx?action=view&msg=true");
            }

            if (btnSave.Text == "Update")
            {
                Response.Redirect("RecieptFormat.aspx?action=view&msg=Update");
            }

        }
        catch (Exception ex)
        {
            lblMsg.Text = ex.Message;
        }

    }
    protected void btnCancel_OnClick(object sender, EventArgs e)
    {
        if (btnSave.Text == "Update")
        {
            Response.Redirect("RecieptFormat.aspx?action=view");
        }
        else
        {
            Response.Redirect("TransactionFormat.aspx");
        }
    }
    private void _SaveTranFormatMain(string FormatId)
    {
        try
        {
            if (FormatId.ToString() != string.Empty)
            {
                if (_CheckDuplicateFormatName(txtFormatName.Text, FormatId))
                {
                    SqlParameter[] sparam ={                                       
                                   new SqlParameter("@FORMATID",FormatId.ToString()),
                                   new SqlParameter("@FORMATNAME",txtFormatName.Text.Trim()),
                                   new SqlParameter("@SETASDEFAULT",chkDefualt.Checked),
                                   new SqlParameter("@TRANSACTIONTYPE","2"),
                                   new SqlParameter("@YEARREFERENCE","0"),
                                   new SqlParameter("@UNITRATE","0"),
                                   new SqlParameter("@ADDDESC","0"),
                                   new SqlParameter("@POSTBILLING","0"),
                                   new SqlParameter("@TAXINCLUSIVE","0"),
                                   new SqlParameter("@NONTAXABLE","0"),
                                   new SqlParameter("@UOM","0"),
                                   new SqlParameter("@NARRATION",chkNarration.Checked),
                                   new SqlParameter("@REMARKS","0"),
                                   new SqlParameter("@PREPAREDBY",chkPreparedBy.Checked),
                                   new SqlParameter("@SERVICEDBY","0"),
                                   new SqlParameter("@CHECKEDBY",chkCheckedBy.Checked),
                                   new SqlParameter("@REFERENCENUMBER",chkReferenceNumber.Checked),
                                   new SqlParameter("@PRINTONSAVE",chkPrinOnSave.Checked),
                                   new SqlParameter("@SHOWSERVICECHARGE","0"),
                                   new SqlParameter("@CNAME",Session["username"].ToString())
                               };
                    FormatId = DU.ExecuteProcedure_Scope_Identity("USP_IVC_SaveTransactionFormat", sparam);
                    _SaveTranFormat_AdditionalUnits(FormatId);
                    _SaveTranFormat_Captions(FormatId);
                    _SaveTranFormat_HeadOfAccounts(FormatId);
                    _SaveTranFormat_Numbers(FormatId);
                    _SaveTranFormat_PostBilling(FormatId);
                    _SaveTranFormat_ReportSettings(FormatId);
                    _SaveTranFormat_TaxDiscountDetails(FormatId);
                    _SaveAcc_TransactionMain(FormatId);
                }
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

    private void _SaveTranFormat_AdditionalUnits(string FormatId)
    {
        try
        {
            if (FormatId != string.Empty)
            {
                SqlParameter[] sparam ={
                                   new SqlParameter("@FORMATID",FormatId),
                                   new SqlParameter("@UNIT1","0"),
                                   new SqlParameter("@UNIT2","0"),
                                   new SqlParameter("@UNIT3","0"),
                                   new SqlParameter("@UNIT1MAIN_CAPTION",""),
                                   new SqlParameter("@UNIT1_FORMULA",""),
                                   new SqlParameter("@GRSFORMULA",""),
                                   new SqlParameter("@UNIT1_CAPTION","Unit2"),
                                   new SqlParameter("@UNIT2_CAPTION","Unit3"),
                                   new SqlParameter("@UNIT3_CAPTION","Unit4")                                   
                               };
                int Result = DU.executeprocedure("USP_IVC_SaveTransactionFormat_AdditionalUnits", sparam);
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    private void _SaveTranFormat_Captions(string FormatId)
    {
        try
        {
            if (FormatId != string.Empty)
            {
                SqlParameter[] sparam ={
                                   new SqlParameter("@FORMATID",FormatId),
                                   new SqlParameter("@UNIT",""),
                                   new SqlParameter("@RATE",""),
                                   new SqlParameter("@YEARREFERENCE",""),
                                   new SqlParameter("@ADDDESCRIPTION",""),
                                   new SqlParameter("@UOM","")
                               };
                int Result = DU.executeprocedure("USP_IVC_SaveTransactionFormat_Captions", sparam);
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

    private void _SaveTranFormat_HeadOfAccounts(string FormatId)
    {
        try
        {
            if (FormatId != string.Empty)
            {
                SqlParameter[] sparam ={
                                   new SqlParameter("@FORMATID",FormatId),
                                   new SqlParameter("@ROUNDOFF_LEDGERID","0"),
                                   new SqlParameter("@DISCOUNT_LEDGERID","0"),
                                   new SqlParameter("@WRITEOFF_LEDGERID",ddlWriteOffAccount.SelectedValue),
                                   new SqlParameter("@TDS_LEDGERID",ddlTDSAccounts.SelectedValue)
                                   
                               };
                int Result = DU.executeprocedure("USP_IVC_SaveTransactionFormat_HeadOfAccounts", sparam);
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

    private void _SaveTranFormat_Numbers(string FormatId)
    {
        try
        {
            if (FormatId != string.Empty)
            {
                SqlParameter[] sparam ={
                                   new SqlParameter("@FINYEAR",Session["FINYEAR"].ToString()),
                                   new SqlParameter("@FORMATID",FormatId),
                                   new SqlParameter("@NUMBERINGMETHOD",ddlType.SelectedValue),
                                   new SqlParameter("@PREFIX",txtPrefix.Text.Trim()),
                                   new SqlParameter("@STARTNUMBER",txtStartNo.Text.Trim()),
                                   new SqlParameter("@SUFFIX",txtSuffix.Text.Trim()),
                                   new SqlParameter("@NUMWIDTH",txtWidthofNo.Text.Trim()),
                                   new SqlParameter("@PREFILLZERO","0"),
                                   new SqlParameter("@RESETYEAR",chkResetYear.Checked)                                  
                               };
                int Result = DU.executeprocedure("USP_IVC_SaveTransactionFormat_Numbers", sparam);
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    private void _SaveTranFormat_PostBilling(string FormatId)
    {
        try
        {
            if (FormatId != string.Empty)
            {
                SqlParameter[] sparam ={
                                   new SqlParameter("@FORMATID",FormatId),
                                   new SqlParameter("@AMTCESS","0"),
                                   new SqlParameter("@TDSRATE","0"),
                                   new SqlParameter("@CESS1RATE","0"),
                                   new SqlParameter("@CESS2RATE","0"),
                                   new SqlParameter("@SURCHARGERATE","0"),
                                   new SqlParameter("@EFFECTIVERATE","0")                                   
                               };
                int Result = DU.executeprocedure("USP_IVC_SaveTransactionFormat_PostBilling", sparam);
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

    private void _SaveTranFormat_ReportSettings(string FormatId)
    {
        try
        {
            if (FormatId != string.Empty)
            {
                string strLogoPath = string.Empty;
                SqlParameter[] sparam ={
                                   new SqlParameter("@FORMATID",FormatId),
                                   new SqlParameter("@CAPTIONYN",chkBillCaption.Checked),
                                   new SqlParameter("@CAPTION",txtBillCaption.Text.Trim()),
                                   new SqlParameter("@FIRMNAME",txtFirmCaption.Text.Trim()),
                                   new SqlParameter("@INFORMATIONYN",chkInfoBeforeDetails.Checked),
                                   new SqlParameter("@INFORMATION",txtInfoBeforeDetails.Text.Trim()),
                                   new SqlParameter("@NOTEYN",chkNote.Checked),
                                   new SqlParameter("@NOTE",txtNote.Text.Trim()),
                                   new SqlParameter("@LOGOYN",chkPrintLogo.Checked),
                                   //new SqlParameter("@LOGOPATH",strLogoPath),
                                   new SqlParameter("@PAGESETYN",chkPageSettings.Checked),
                                   new SqlParameter("@HEADMARGIN",txtHeaderMargin.Text.Trim()),
                                   new SqlParameter("@FOOTMARGIN",txtFooterMargin.Text.Trim()),
                                   new SqlParameter("@NOOFCOPY",txtNoOfCopy.Text.Trim()),
                                   new SqlParameter("@PAPERSIZE",ddlPaperSize.SelectedValue),
                                   new SqlParameter("@FIRMNAMEADDRYN",chkReportFirmNameAddress.Checked),
                                   new SqlParameter("@CNAMEADDRYN",chkReportCustomerName.Checked),
                                   new SqlParameter("@PANYN","0"),
                                   new SqlParameter("@STREGNOYN",chkReportSTRegNo.Checked),
                                   new SqlParameter("@OUTSUMMARYYN",chkReportOutStandingSummary.Checked),
                                   new SqlParameter("@SERVICEDBYYN","0"),
                                   new SqlParameter("@NARRATIONYN",chkReportNarration.Checked),
                                   new SqlParameter("@PREPAREDBYYN",chkReportPreparedBy.Checked),
                                   new SqlParameter("@CHECKEDBYYN",chkReportCheckedBy.Checked),
                                   new SqlParameter("@REFNOYN",chkReportReferenceNo.Checked)
                               };
                int Result = DU.executeprocedure("USP_IVC_SaveTransactionFormat_ReportSettings", sparam);
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    private void _SaveTranFormat_TaxDiscountDetails(string FormatId)
    {
        try
        {
            if (FormatId != string.Empty)
            {
                SqlParameter[] sparam ={
                                   new SqlParameter("@FORMATID",FormatId),
                                   new SqlParameter("@TAXLEVEL","0"),
                                   new SqlParameter("@DISCOUNTLEVEL","0"),
                                   new SqlParameter("@TAXTYPEID","0"),
                                   new SqlParameter("@TAXCALON","0"),
                                   new SqlParameter("@ITEMTAXTYPE","0")                                
                               };
                int Result = DU.executeprocedure("USP_IVC_SaveTransactionFormat_Tax_Discount_Details", sparam);
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

    private bool _CheckDuplicateFormatName(string FormatName, string FormatId)
    {
        bool flag = true;
        SqlParameter[] sparam ={
                                   new SqlParameter("@FORMATNAME",FormatName),
                                   new SqlParameter("@FORMATID",FormatId)
                              };
        DataTable DTDuplicate = DU.getdatausingprocedure("USP_IVC_IsFormatNameExists", sparam);
        if (DTDuplicate.Rows.Count > 0 && Convert.ToDouble(DTDuplicate.Rows[0]["FormatName"].ToString()) > 0)
        {
            lblMsg.Text = "Duplicate Format Name";
            flag = false;
        }
        else
        {
            flag = true;
        }
        return flag;
    }
    private void _SaveAcc_TransactionMain(string FormatId)
    {
        try
        {
            if (FormatId != string.Empty)
            {
                string[] Date1 = string.Format("{0:MM/dd/yyyy}", Convert.ToDateTime(System.DateTime.Now)).ToString().Split('/');
                string effectiveDate = Date1[0].ToString() + "/" + Date1[1].ToString() + "/" + Date1[2].ToString();
                SqlParameter[] sparam =
                                        {
                                            
                                            new SqlParameter("@TYPEID", hidTypeId.Value),
                                            new SqlParameter("@PARENTTYPEID","9"),
                                            new SqlParameter("@TRANSACTIONNAME",txtFormatName.Text.Trim()),
                                            new SqlParameter("@ISAUTONO",ddlType.SelectedValue),
                                            new SqlParameter("@RESETNO",chkResetYear.Checked),
                                            new SqlParameter("@ISREFERENCE","0"),                                                
                                            new SqlParameter("@ISDEFAULTNARRATION","0"),
                                            new SqlParameter("@EFFECTIVEDATE",effectiveDate.ToString()),
                                            new SqlParameter("@BILLFORMATID",FormatId.ToString()),
                                            new SqlParameter("@MODULETYPE","3"),
                                            new SqlParameter("@CCALLOCATIONTYPE","0")
                                        };
                string strTypeId = DU.ExecuteProcedure_Scope_Identity("USP_ACC_SaveTransactionSetting", sparam);
                if (strTypeId != string.Empty)
                {
                    _SaveAcc_TransactionDetails(strTypeId);
                }
            }
        }
        catch (Exception ex)
        {
            throw ex;

        }
    }
    private void _SaveAcc_TransactionDetails(string strAccTypeId)
    {
        try
        {
            if (strAccTypeId.ToString() != string.Empty)
            {

                SqlParameter[] sparam =
                                            {
                                                new SqlParameter("@TYPEID",strAccTypeId.ToString()),
                                                new SqlParameter("@FINYEAR",Session["FINYEAR"].ToString()), 
                                                new SqlParameter("@STARTNO",txtStartNo.Text.Trim()),
                                                new SqlParameter("@PREFIX",txtPrefix.Text.Trim()),
                                                new SqlParameter("@SUFFIX",txtSuffix.Text.Trim()),
                                                new SqlParameter("@ACCLEVELNARRATION","0"),
                                                new SqlParameter("@PRINTONSAVE","0")

                                            };
                DU.executeprocedure("USP_ACC_SaveTransactionSettingDetail", sparam);

            }
        }
        catch (Exception ex)
        {
            throw ex;
        }

    }

    private void _BindEditTranFormat_Main(string strFormatId)
    {
        if (strFormatId != string.Empty)
        {
            SqlParameter[] sparam ={
                                       new SqlParameter("@FORMATID",strFormatId)
                                   };
            DataTable DTFormatMain = DU.getdatausingprocedure("USP_IVC_GetTransactionFormat", sparam);
            if (DTFormatMain.Rows.Count > 0)
            {
                txtFormatName.Text = DTFormatMain.Rows[0]["FORMATNAME"].ToString();
                chkDefualt.Checked = Convert.ToBoolean(DTFormatMain.Rows[0]["SETASDEFAULT"].ToString());
                chkPreparedBy.Checked = Convert.ToBoolean(DTFormatMain.Rows[0]["PREPAREDBY"].ToString());
                chkPrinOnSave.Checked = Convert.ToBoolean(DTFormatMain.Rows[0]["PRINTONSAVE"].ToString());
                chkReferenceNumber.Checked = Convert.ToBoolean(DTFormatMain.Rows[0]["REFERENCENUMBER"].ToString());
                //chkRemarks.Checked = Convert.ToBoolean(DTFormatMain.Rows[0]["REMARKS"].ToString());
                chkNarration.Checked = Convert.ToBoolean(DTFormatMain.Rows[0]["NARRATION"].ToString());
                chkCheckedBy.Checked = Convert.ToBoolean(DTFormatMain.Rows[0]["CHECKEDBY"].ToString());
                _BindEditTranFormat_Numbers(strFormatId);
                _BindEditTranFormat_HeadOfAccounts(strFormatId);
                _BindEditTranFormat_ReportSettings(strFormatId);

            }
            SqlParameter[] sparam1 ={
                                        new SqlParameter("@PARENTTYPEID","9"),
                                        new SqlParameter("@BILLFORMATID",strFormatId),
                                        new SqlParameter("@MODULETYPE","3")
                                   };
            DataTable DTTypeId = DU.getdatausingprocedure("USP_ACC_GetTransactionSettingBasedOnFormat", sparam1);
            if (DTTypeId.Rows.Count > 0)
            {
                hidTypeId.Value = DTTypeId.Rows[0]["TYPEID"].ToString();
            }
        }
    }
    private void _BindEditTranFormat_Numbers(string strFormatId)
    {
        if (strFormatId != string.Empty)
        {
            SqlParameter[] sparam ={
                                        new SqlParameter("@FORMATID",strFormatId),
                                        new SqlParameter("@FINYEAR",Session["FINYEAR"].ToString())
                                   };
            DataTable DTFormatNumber = DU.getdatausingprocedure("USP_IVC_GetTransactionFormat_Numbers", sparam);
            if (DTFormatNumber.Rows.Count > 0)
            {
                txtPrefix.Text = DTFormatNumber.Rows[0]["PREFIX"].ToString();
                txtStartNo.Text = DTFormatNumber.Rows[0]["STARTNUMBER"].ToString();
                txtSuffix.Text = DTFormatNumber.Rows[0]["SUFFIX"].ToString();
                txtWidthofNo.Text = DTFormatNumber.Rows[0]["NUMWIDTH"].ToString();
                chkResetYear.Checked = Convert.ToBoolean(DTFormatNumber.Rows[0]["RESETYEAR"].ToString());
                ddlType.SelectedValue = DTFormatNumber.Rows[0]["NUMBERINGMETHOD"].ToString();

            }
        }
    }
    private void _BindEditTranFormat_HeadOfAccounts(string strFormatId)
    {
        if (strFormatId != string.Empty)
        {
            SqlParameter[] sparam ={
                                       new SqlParameter("@FORMATID",strFormatId)
                                   };
            DataTable DTFormatHead = DU.getdatausingprocedure("USP_IVC_GetTransactionFormat_HeadOfAccounts", sparam);
            if (DTFormatHead.Rows.Count > 0)
            {
                ddlTDSAccounts.SelectedValue = DTFormatHead.Rows[0]["TDS_LEDGERID"].ToString();
                ddlWriteOffAccount.SelectedValue = DTFormatHead.Rows[0]["WRITEOFF_LEDGERID"].ToString();
            }
        }
    }
    private void _BindEditTranFormat_ReportSettings(string strFormatId)
    {
        if (strFormatId != string.Empty)
        {
            SqlParameter[] sparam ={
                                        new SqlParameter("@FORMATID",strFormatId)
                                        
                                   };
            DataTable DTFormatReport = DU.getdatausingprocedure("USP_IVC_GetTransactionFormat_ReportSettings", sparam);
            if (DTFormatReport.Rows.Count > 0)
            {
                chkBillCaption.Checked = Convert.ToBoolean(DTFormatReport.Rows[0]["CAPTIONYN"].ToString());
                if (DTFormatReport.Rows[0]["CAPTIONYN"].ToString() == "True")
                {
                    txtBillCaption.Enabled = true;
                    txtBillCaption.Text = DTFormatReport.Rows[0]["CAPTION"].ToString();
                }
                else
                {
                    txtBillCaption.Enabled = false;
                }

                txtFirmCaption.Text = DTFormatReport.Rows[0]["FIRMNAME"].ToString();
                chkInfoBeforeDetails.Checked = Convert.ToBoolean(DTFormatReport.Rows[0]["INFORMATIONYN"].ToString());
                if (DTFormatReport.Rows[0]["INFORMATIONYN"].ToString() == "True")
                {
                    txtInfoBeforeDetails.Enabled = true;
                    txtInfoBeforeDetails.Text = DTFormatReport.Rows[0]["INFORMATION"].ToString();
                }
                else
                {
                    txtInfoBeforeDetails.Enabled = false;
                }


                chkNote.Checked = Convert.ToBoolean(DTFormatReport.Rows[0]["NOTEYN"].ToString());

                if (DTFormatReport.Rows[0]["NOTEYN"].ToString() == "True")
                {
                    txtNote.Enabled = true;
                    txtNote.Text = DTFormatReport.Rows[0]["NOTE"].ToString();
                }
                else
                {
                    txtNote.Enabled = false;
                }
                // hidFileUpload.Value = DTFormatReport.Rows[0]["LOGOPATH"].ToString();
                chkPrintLogo.Checked = Convert.ToBoolean(DTFormatReport.Rows[0]["LOGOYN"].ToString());
                chkPageSettings.Checked = Convert.ToBoolean(DTFormatReport.Rows[0]["PAGESETYN"].ToString());
                if (DTFormatReport.Rows[0]["PAGESETYN"].ToString() == "True")
                {
                    txtHeaderMargin.Text = "0.5";
                    txtHeaderMargin.Enabled = false;
                    txtFooterMargin.Text = "0.5";
                    txtFooterMargin.Enabled = false;
                }
                else
                {
                    txtHeaderMargin.Enabled = true;
                    txtHeaderMargin.Text = DTFormatReport.Rows[0]["HEADMARGIN"].ToString();
                    txtFooterMargin.Text = DTFormatReport.Rows[0]["FOOTMARGIN"].ToString();
                    txtFooterMargin.Enabled = true;
                }
                txtNoOfCopy.Text = DTFormatReport.Rows[0]["NOOFCOPY"].ToString();


                if (DTFormatReport.Rows[0]["PAPERSIZE"].ToString() == "True")
                {
                    ddlPaperSize.SelectedValue = "1";
                }

                chkReportCheckedBy.Checked = Convert.ToBoolean(DTFormatReport.Rows[0]["CHECKEDBYYN"].ToString());
                chkReportCustomerName.Checked = Convert.ToBoolean(DTFormatReport.Rows[0]["CNAMEADDRYN"].ToString());
                chkReportFirmNameAddress.Checked = Convert.ToBoolean(DTFormatReport.Rows[0]["FIRMNAMEADDRYN"].ToString());
                chkReportOutStandingSummary.Checked = Convert.ToBoolean(DTFormatReport.Rows[0]["OUTSUMMARYYN"].ToString());
                chkReportPreparedBy.Checked = Convert.ToBoolean(DTFormatReport.Rows[0]["PREPAREDBYYN"].ToString());
                chkReportSTRegNo.Checked = Convert.ToBoolean(DTFormatReport.Rows[0]["STREGNOYN"].ToString());
            }
        }
    }
    private void _BindGridViewData()
    {
        SqlParameter[] sparam ={
                                       new SqlParameter("@TRANSACTIONTYPE","2")
                                   };
        DataTable DTFormatMain = DU.getdatausingprocedure("USP_IVC_GetAllTransactionFormats", sparam);
        grdDisplay.DataSource = DTFormatMain;
        grdDisplay.DataBind();
    }
    protected void grdDisplay_OnRowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.Cells[2].Text == "True")
            {
                e.Row.Cells[2].Text = "Yes";
            }
            else
            {
                e.Row.Cells[2].Text = "No";
            }
            if (e.Row.Cells[3].Text == "True")
            {
                e.Row.Cells[3].Text = "Yes";
            }
            else
            {
                e.Row.Cells[3].Text = "No";
            }
            if (e.Row.Cells[4].Text == "True")
            {
                e.Row.Cells[4].Text = "Yes";
            }
            else
            {
                e.Row.Cells[4].Text = "No";
            }
            if (e.Row.Cells[5].Text == "True")
            {
                e.Row.Cells[5].Text = "Yes";
            }
            else
            {
                e.Row.Cells[5].Text = "No";
            }
            if (e.Row.Cells[6].Text == "True")
            {
                e.Row.Cells[6].Text = "Yes";
            }
            else
            {
                e.Row.Cells[6].Text = "No";
            }
            if (e.Row.Cells[7].Text == "True")
            {
                e.Row.Cells[7].Text = "Yes";
            }
            else
            {
                e.Row.Cells[7].Text = "No";
            }

            if (e.Row.Cells[8].Text == "True")
            {
                e.Row.Cells[8].Text = "Yes";
            }
            else
            {
                e.Row.Cells[8].Text = "No";
            }
        }
    }
    protected void grdDidplay_OnSelectedIndexChanged(object sender, EventArgs e)
    {
        string strDataKey = grdDisplay.SelectedDataKey.Value.ToString();
        Response.Redirect("RecieptFormat.aspx?Status=Edit&action=Edit&FormatId=" + strDataKey);
    }
}
